package com.xukai.springboot.controller.statistics;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xukai.springboot.entity.response.ResponseBase;
import com.xukai.springboot.entity.response.statis.StatisDataResponse;
import com.xukai.springboot.entity.statistics.t_statis_column;
import com.xukai.springboot.entity.statistics.t_statis_data;
import com.xukai.springboot.service.statistics.DataCaptureService;
import com.xukai.springboot.service.statistics.StatisDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api(basePath = "api/statis", description = "数据统计")
@RestController
@RequestMapping("api/statis")
public class StatisticsController {

    /**
     * 日志
     */
    private final Logger logger = LoggerFactory.getLogger(StatisticsController.class);

    @Autowired
    private StatisDataService statisDataService;


    /**
     * 获取统计数据
     *
     * @param dataSourceID
     * @return
     */
    @ApiOperation(value = "获取统计数据", notes = "获取统计数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dataSourceID", value = "数据源ID", required = true, dataType = "int",example = "0",defaultValue = "0", paramType = "query")
    })
    @GetMapping("GetStatisData")
    public ResponseBase<StatisDataResponse> GetStatisData(@RequestParam int dataSourceID) {
        ResponseBase<StatisDataResponse> result = new ResponseBase<StatisDataResponse>();
        try {
            StatisDataResponse data = new StatisDataResponse();
            result.setData(data);
            data.setDataSourceID(dataSourceID);
            t_statis_data statis_data = statisDataService.GetDataByDataSourceID(dataSourceID);
            if (statis_data == null) {
                return result;
            }
            data.setJsonDataStr( statis_data.getData());

        } catch (Exception e) {
            logger.error("获取统计数", e);
            result.setStatue(0);
        }
        return result;
    }

}
